#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// 2009. 使数组连续的最少操作数
// https://leetcode.cn/problems/minimum-number-of-operations-to-make-array-continuous/description/

class Solution
{
public:
    int minOperations(vector<int> &nums)
    {
        sort(nums.begin(), nums.end());

        int n = nums.size();
        int m = unique(nums.begin(), nums.end()) - nums.begin();
        int ret = 0;
        int left = 0;
        for (int i = 0; i < m; i++)
        {
            while (nums[i] - nums[left] + 1 > n)
            {
                left++;
            }
            ret = max(ret, i - left + 1);
        }
        return n - ret;
    }
};

int main()
{
    return 0;
}